/**
 * 
 */
package root.board.pieces;

import root.board.Piece;
import root.board.moviment.Moviment;
import root.board.moviment.Position;

/**
 * @author Calebe
 * 
 */
public class Pawn extends Piece {

	/**
	 * 
	 */
	public Pawn() {
		super();
	}

	/**
	 * @param team
	 */
	public Pawn(int team) {
		setTeam(team);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see root.board.PieceInterface#moviments(int, int)
	 */
	@Override
	public Moviment[] moviments(int xPosition, int yPosition) {
		boolean pawnMoved = false;
		Moviment[] moviments = new Moviment[0];
		int movimentCount = 0;
		if (getTeam() == Piece.NORTH) {
			if (yPosition != 1)
				pawnMoved = true;
			if (pawnMoved)
				moviments = new Moviment[3];
			else
				moviments = new Moviment[4];

			if (!pawnMoved)
				moviments[movimentCount++] = new Moviment(new Position(xPosition, yPosition),
						new Position(xPosition, yPosition + 2));

			if (yPosition != 7)
				moviments[movimentCount++] = new Moviment(new Position(xPosition, yPosition),
						new Position(xPosition, yPosition + 1));
			if (xPosition != 7 && yPosition != 7)
				moviments[movimentCount++] = new Moviment(new Position(xPosition, yPosition),
						new Position(xPosition + 1, yPosition + 1));
			if (xPosition != 0 && yPosition != 7)
				moviments[movimentCount++] = new Moviment(new Position(xPosition, yPosition),
						new Position(xPosition - 1, yPosition + 1));
		} else {
			if (yPosition != 6)
				pawnMoved = true;
			if (pawnMoved)
				moviments = new Moviment[3];
			else
				moviments = new Moviment[4];

			if (!pawnMoved)
				moviments[movimentCount++] = new Moviment(new Position(xPosition, yPosition),
						new Position(xPosition, yPosition - 2));

			if (yPosition != 7)
				moviments[movimentCount++] = new Moviment(new Position(xPosition, yPosition),
						new Position(xPosition, yPosition - 1));
			if (xPosition != 7 && yPosition != 7)
				moviments[movimentCount++] = new Moviment(new Position(xPosition, yPosition),
						new Position(xPosition + 1, yPosition - 1));
			if (xPosition != 0 && yPosition != 7)
				moviments[movimentCount++] = new Moviment(new Position(xPosition, yPosition),
						new Position(xPosition - 1, yPosition - 1));

		}
		return moviments;
	}

}
